chrome.extension
Description: |
The chrome.extension API has utilities that can be used by any extension page. It includes support for exchanging messages between an extension and its content scripts or between extensions, as described in detail in Message Passing.
|
Availability: |
Since Chrome 35.
|
Content Scripts: |
getURL
,
inIncognitoContext
,
lastError
,
onRequest
and
sendRequest
are supported.
Learn more
|
Summary
Types | |
---|---|
ViewType | |
Properties | |
lastError | |
inIncognitoContext | |
Methods | |
sendRequest −
chrome.extension.sendRequest(string extensionId, any request, function responseCallback)
| |
getURL −
string
chrome.extension.getURL(string path)
| |
getViews −
array of Window
chrome.extension.getViews(object fetchProperties)
| |
getBackgroundPage −
Window
chrome.extension.getBackgroundPage()
| |
getExtensionTabs −
array of Window
chrome.extension.getExtensionTabs(integer windowId)
| |
isAllowedIncognitoAccess −
chrome.extension.isAllowedIncognitoAccess(function callback)
| |
isAllowedFileSchemeAccess −
chrome.extension.isAllowedFileSchemeAccess(function callback)
| |
setUpdateUrlData −
chrome.extension.setUpdateUrlData(string data)
| |
Events | |
onRequest | |
onRequestExternal |
Types
ViewType
Enum |
---|
"tab" ,
or "popup"
|
Properties
object | chrome.extension.lastError |
Deprecated since Chrome 58. Please use runtime.lastError. Set for the lifetime of a callback if an ansychronous extension api has resulted in an error. If no error has occured lastError will be undefined.
|
||||||
boolean | chrome.extension.inIncognitoContext |
True for content scripts running inside incognito tabs, and for extension pages running inside an incognito process. The latter only applies to extensions with 'split' incognito_behavior. |
Methods
sendRequest
chrome.extension.sendRequest(string extensionId, any request, function responseCallback)
Deprecated since Chrome 35. Please use runtime.sendMessage.
Sends a single request to other listeners within the extension. Similar to runtime.connect, but only sends a single request with an optional response. The extension.onRequest event is fired in each page of the extension.
Parameters | |||||
---|---|---|---|---|---|
string | (optional) extensionId |
The extension ID of the extension you want to connect to. If omitted, default is your own extension. |
|||
any | request | ||||
function | (optional) responseCallback |
If you specify the responseCallback parameter, it should be a function that looks like this: function(any response) {...};
|
getURL
string
chrome.extension.getURL(string path)
Deprecated since Chrome 58. Please use runtime.getURL.
Converts a relative path within an extension install directory to a fully-qualified URL.
Parameters | ||
---|---|---|
string | path |
A path to a resource within an extension expressed relative to its install directory. |
getViews
array of Window
chrome.extension.getViews(object fetchProperties)
Returns an array of the JavaScript 'window' objects for each of the pages running inside the current extension.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | (optional) fetchProperties |
|
getBackgroundPage
Window
chrome.extension.getBackgroundPage()
Returns the JavaScript 'window' object for the background page running inside the current extension. Returns null if the extension has no background page.
Returns
getExtensionTabs
array of Window
chrome.extension.getExtensionTabs(integer windowId)
Deprecated since Chrome 35.
Please use extension.getViews {type: "tab"}
.
Returns an array of the JavaScript 'window' objects for each of the tabs running inside the current extension. If windowId
is specified, returns only the 'window' objects of tabs attached to the specified window.
Parameters | ||
---|---|---|
integer | (optional) windowId |
isAllowedIncognitoAccess
chrome.extension.isAllowedIncognitoAccess(function callback)
Retrieves the state of the extension's access to Incognito-mode (as determined by the user-controlled 'Allowed in Incognito' checkbox.
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(boolean isAllowedAccess) {...};
|
isAllowedFileSchemeAccess
chrome.extension.isAllowedFileSchemeAccess(function callback)
Retrieves the state of the extension's access to the 'file://' scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox.
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(boolean isAllowedAccess) {...};
|
setUpdateUrlData
chrome.extension.setUpdateUrlData(string data)
Sets the value of the ap CGI parameter used in the extension's update URL. This value is ignored for extensions that are hosted in the Chrome Extension Gallery.
Parameters | ||
---|---|---|
string | data |
Events
onRequest
Deprecated since Chrome 35. Please use runtime.onMessage.
Fired when a request is sent from either an extension process or a content script.
addListener
chrome.extension.onRequest.addListener(function callback)
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(any request, runtime.MessageSender sender, function sendResponse) {...};
|
onRequestExternal
Deprecated since Chrome 35. Please use runtime.onMessageExternal.
Fired when a request is sent from another extension.
addListener
chrome.extension.onRequestExternal.addListener(function callback)
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(any request, runtime.MessageSender sender, function sendResponse) {...};
|